/*
 * Copyright (C) 2013 by Osama Abdelkhaleq, Andrew Foxworth, Jasmine Griffiths, Kyle Kenik
 * -----------------------------------------------------------------------------------------
 * 
 * This file is part of
 * 
 * MovSimDroid.
 * 
 * MovSimDroid is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * MovSimDroid is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with MovSim. If not, see <http://www.gnu.org/licenses/>
 * or <http://www.movsim.org>.
 * 
 * -----------------------------------------------------------------------------------------
 */
package org.movsim.movdroid;

/*
 * This activity allows users to set the duration of traffic light phases
 * for the intersection scenario using slider bars.
 */

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.Toast;

public class TrafficLightConfigOneSet extends Activity implements SeekBar.OnSeekBarChangeListener {
	
	int red, yellow, green;
	SeekBar red1,yellow1, green1;	//1 = North/South 2 = East/West
	String light1, light2;
	Button finished;
	
	
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.traffic_light_one_set);
			
		Bundle bundle = this.getIntent().getExtras();
		red = bundle.getInt("red");
		yellow = bundle.getInt("yellow");
		green = bundle.getInt("green");
		
		// initialize the red seek bars
		red1 = (SeekBar) findViewById(R.id.redSeekBar1);
		
		// initialize the yellow seek bars
		yellow1 = (SeekBar) findViewById(R.id.yellowSeekBar1);
				
		// initialise the green seek bar
		green1 = (SeekBar) findViewById(R.id.greenSeekBar1);
				
		if (red != -1 && yellow != -1 && green != -1){
			red1.setProgress(red);
			yellow1.setProgress(yellow);
			green1.setProgress(green);
		}
		
		red1.setOnSeekBarChangeListener(this);
		yellow1.setOnSeekBarChangeListener(this);
		green1.setOnSeekBarChangeListener(this);
		
		finished = (Button) findViewById(R.id.button_Ok);
	
		finished.setOnClickListener(new View.OnClickListener() {
			public void onClick(View view) {
				System.out.println(red + " " + yellow + " " + green);
				Intent data = new Intent();
				data.putExtra("red", red);
				data.putExtra("yellow", yellow);
				data.putExtra("green", green);
				setResult(RESULT_OK, data);
				finish();
			}
		});
	}


	@Override
	public void onProgressChanged(SeekBar seekBar, int progress,
			boolean fromUser) {
		// TODO Auto-generated method stub
		switch (seekBar.getId()){
		case R.id.redSeekBar1:
			red = progress;			
			break;
		case R.id.yellowSeekBar1:
			yellow = progress;			
			break;
		case R.id.greenSeekBar1:
			green = progress;			
			break;
		}
	}


	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
		
	}


	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
		
	}
}
